import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/widget/custom_list_title.dart';
import 'package:boss/ui/widget/image/base_image.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class TitleRowButton extends StatelessWidget {
  final dynamic title;
  final dynamic subTitle;
  final int childHeight;
  final String hintText;
  final String value;
  final VoidCallback onTap;
  final bool isRequired;
  final bool isHideIcon;
  final TextStyle valueTextStyle;
  final bool enabled;

  const TitleRowButton({
    Key key,
    @required this.title,
    this.hintText,
    this.value,
    this.subTitle,
    this.childHeight,
    this.onTap,
    this.isRequired = false,
    this.isHideIcon = false,
    this.valueTextStyle,
    this.enabled = true,
  }) : super(key: key);

  bool get isShowHint => value == null || value == '';

  @override
  Widget build(BuildContext context) {
    return CustomListTitle(
      title: Row(
        children: <Widget>[
          title is String
              ? Text(
                  title,
                  style: TextStyleConstant().normal_1_28,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                )
              : title,
          if (isRequired) Text('*', style: TextStyleConstant().origin_28),
        ],
      ),
      trailing: Expanded(
        child: Padding(
          padding: EdgeInsets.only(left: 15.w),
          child: Row(
            children: <Widget>[
              Expanded(
                child: Text(
                  isShowHint ? hintText : value,
                  style: isShowHint ? TextStyleConstant().normal_4_28 : valueTextStyle ?? TextStyleConstant().normal_1_28,
                  overflow: TextOverflow.ellipsis,
                  textAlign: TextAlign.end,
                ),
              ),
              if (!isHideIcon)
                Container(
                  margin: EdgeInsets.only(
                    left: 10.w,
                  ),
                  child: BaseImage(
                    'assets/image/arrow_right_icon.png',
                    width: 13.w,
                    height: 30.w,
                  ),
                ),
            ],
          ),
        ),
      ),
      subTitle: subTitle,
      childHeight: childHeight,
      onTap: enabled ? onTap : null,
    );
  }
}
